HAL USART types migration

This section provides information about the HAL USART types migration .

HAL USART enumeration migration

HAL USART states type definition

In HAL2, key changes include:
  1. Renaming of several states.

  2. Removal of states HAL_USART_STATE_TIMEOUT and HAL_USART_STATE_ERROR.

  3. Adding a new state HAL_USART_STATE_ABORT

HAL1

HAL2

typedef enum
{
  HAL_USART_STATE_RESET,
  HAL_USART_STATE_READY,
  HAL_USART_STATE_BUSY,
  HAL_USART_STATE_BUSY_TX,
  HAL_USART_STATE_BUSY_RX,
  HAL_USART_STATE_BUSY_TX_RX,
  HAL_USART_STATE_TIMEOUT,
  HAL_USART_STATE_ERROR
} HAL_USART_StateTypeDef;
typedef enum
{
  HAL_USART_STATE_RESET,
  HAL_USART_STATE_INIT,
  HAL_USART_STATE_IDLE,
  HAL_USART_STATE_RX_ACTIVE,
  HAL_USART_STATE_TX_ACTIVE,
  HAL_USART_STATE_TX_RX_ACTIVE,
  HAL_USART_STATE_ABORT
} hal_usart_state_t;

HAL USART callback ID type definition

HAL1

HAL2

typedef enum
{
  HAL_USART_TX_HALFCOMPLETE_CB_ID
  HAL_USART_TX_COMPLETE_CB_ID
  HAL_USART_RX_HALFCOMPLETE_CB_ID
  HAL_USART_RX_COMPLETE_CB_ID
  HAL_USART_TX_RX_COMPLETE_CB_ID
  HAL_USART_ERROR_CB_ID
  HAL_USART_ABORT_COMPLETE_CB_ID
  HAL_USART_RX_FIFO_FULL_CB_ID
  HAL_USART_TX_FIFO_EMPTY_CB_ID

  HAL_USART_MSPINIT_CB_ID
  HAL_USART_MSPDEINIT_CB_ID

} HAL_USART_CallbackIDTypeDef

Removed.

Note

The callback registration in HAL2 is handled by specific functions for each USART event. See Register Callbacks for more details.

HAL_USART_MSPINIT_CB_ID and HAL_USART_MSPDEINIT_CB_ID are removed because the functions HAL_USART_MspInit() and HAL_USART_MspDeInit() are removed.

Related concept:


HAL USART clock source type definition

HAL1

HAL2

typedef enum
{
  USART_CLOCKSOURCE_PCLK1,
  USART_CLOCKSOURCE_PCLK2,
  USART_CLOCKSOURCE_HSI,
  USART_CLOCKSOURCE_SYSCLK,
  USART_CLOCKSOURCE_LSE,
  USART_CLOCKSOURCE_UNDEFINED
} USART_ClockSourceTypeDef;

Removed: In HAL1, this structure was used internally for baudrate calculations and was not exposed to the user.


HAL USART structure migration

HAL USART handle type definition

HAL1

HAL2

USART_HandleTypeDef

hal_usart_handle_t

Related concept:


HAL USART initialization type definition

HAL1

HAL2

typedef struct
{
    uint32_t BaudRate;
    uint32_t WordLength;
    uint32_t StopBits;
    uint32_t Parity;
    uint32_t Mode;
    uint32_t CLKPolarity;
    uint32_t CLKPhase;
    uint32_t CLKLastBit;
    uint32_t ClockPrescaler;
} USART_InitTypeDef;
typedef struct
{
    uint32_t baud_rate;
    hal_usart_word_length_t word_length;
    hal_usart_stop_bits_t stop_bits;
    hal_usart_parity_t parity;
    hal_usart_mode_t mode;
    hal_usart_clock_polarity_t clock_polarity;
    hal_usart_clock_phase_t clock_phase;
    hal_usart_clock_last_bit_state_t clock_last_bit;
    hal_usart_prescaler_t clock_prescaler;
} hal_usart_config_t;

Related concept: Replaced TypeDef suffix with _t in type names.


HAL USART autonomous mode configuration type definition

HAL1

HAL2

typedef struct
{
    uint32_t TriggerSelection;
    uint32_t TriggerPolarity;
    uint32_t DataSize;

    uint32_t AutonomousModeState;
    uint32_t IdleFrame;
} USART_AutonomousModeConfTypeDef;
typedef struct
{
    hal_usart_am_trig_source_t source;
    hal_usart_am_trig_polarity_t trigger_polarity;
    uint32_t packet_size_byte;
} hal_usart_am_config_t;

Note

AutonomousModeState and IdleFrame have been removed from the structure. These functionalities are now managed through separate functions. For more details, see the section HAL USART autonomous mode.

Related concept: Replaced TypeDef suffix with _t in type names


HAL USART callback type definition

HAL1

HAL2

pUSART_CallbackTypeDef

hal_usart_cb_t

Related concept: Replaced TypeDef suffix with _t in type names